# -*- coding: utf-8 -*-
# @author: chenhuachao
# @time: 2018/8/6
import time
import random
import hmac
import base64
import hashlib
import requests
import json
import re

appid = '1253358209'
secret_id = 'AKIDLXddS5gu5HSSGv6hnsodHo9IG3jEEjme'
secret_key = 'qX7Xp031pSuGaptlT1QjsvnZH7UmsrfH'
bucket = 'BUCKET'

userid= 0



expired = time.time() + 2592000
onceExpired = 0
current = time.time()
rdm = ''.join(random.choice("0123456789") for i in range(10))

info = "a=" + appid + "&b=" + bucket + "&k=" + secret_id + "&e=" + str(expired) + "&t=" + str(current) + "&r=" + str(
    rdm) + "&u=0&f="


signindex = hmac.new(secret_key, info, hashlib.sha1).digest()  # HMAC-SHA1加密
sign = base64.b64encode(signindex + info)  # base64转码

url = "http://recognition.image.myqcloud.com/ocr/general"
headers = {'Host': 'recognition.image.myqcloud.com',
           "Authorization": sign,
           }
files = {'appid': (None, appid),
         'bucket': (None, bucket),
         'image': ('1.jpg', open('test.jpg', 'rb'), 'image/jpeg')
         }

r = requests.post(url, files=files, headers=headers)
responseinfo = r.content
print(responseinfo)

